$(function () {
  let search = location.search
  let index = search.indexOf('=')
  let id = +search.substring(index + 1)
  $.ajax({
    url: 'http://146.56.230.35:3007/users/getUserById',
    type: 'GET',
    data: { id },
    success(res) {
      if (res.code !== 200) {
        return alert(res.msg)
      }
      let el = `
      <p><strong>用户编号：</strong><span>${res.user.userCode}</span></p>
      <p><strong>用户名称：</strong><span>${res.user.userName}</span></p>
      <p><strong>用户性别：</strong><span>${res.user.gender}</span></p>
      <p><strong>出生日期：</strong><span>${dateFormat(
        res.user.birthday
      )}</span></p>
      <p><strong>用户电话：</strong><span>${res.user.phone}</span></p>
      <p><strong>用户地址：</strong><span>${res.user.address}</span></p>
      <p><strong>用户类别：</strong><span>${res.user.roleName}</span></p>
      <a href="javascript:void(0)" class="goBack">返回</a>`
      $('.providerView').html(el)
      $('.goBack').click(function () {
        history.go(-1)
      })
    },
    error(err) {
      console.error(err)
    },
    headers: { token: getToken().token },
  })
})

function dateFormat(v) {
  let date = v ? new Date(v) : new Date()
  return (
    date.getFullYear() +
    '年' +
    (date.getMonth() + 1) +
    '月' +
    date.getDate() +
    '日'
  )
}
